/*
 * @Author: szx
 * @Date: 2022-05-18 13:28:31
 * @LastEditTime: 2022-05-18 13:38:44
 * @Description:
 * @FilePath: \leetcode\面试题\04\05\05.js
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isValidBST = function (root) {
    let prev = null;
    let res = true;
    const dfs = (root) => {
        if (!root) return;
        dfs(root.left);
        if (!prev) prev = root;
        else {
            if (prev.val >= root.val) {
                res = false;
                return;
            }
            prev = root;
        }
        dfs(root.right);
    };
    dfs(root);
    return res;
};
